using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using JGSY.CMS.LowCode.Platform.Infrastructure.ServiceCollectionExtensions;
using JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.ServiceModules;
using JGSY.CMS.LowCode.Platform.Infrastructure.Extensions;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.MiddlewareModules.Modules
{
    /// <summary>
    /// 系统优化中间件模块
    /// 包含系统级别的优化中间件
    /// </summary>
    public class SystemOptimizationMiddlewareModule : IMiddlewareModule
    {
        public string ModuleName => "系统优化中间件";
        public int Priority => 6;
        public bool EnableInDevelopment => false; // 开发环境不启用
        public bool EnableInProduction => true;
        public bool EnableInFastMode => false; // 快速模式不启用
        public ModulePermission RequiredPermission => ModulePermission.SystemOptimizationServices;
        public bool IsCriticalModule => false; // 非关键中间件

        public void ConfigureMiddleware(WebApplication app, IConfiguration configuration)
        {
            // 延迟加载优化中间件（避免启动时预热）
            app.UseSystemOptimizations();
        }

        public void ConfigureMinimalMiddleware(WebApplication app, IConfiguration configuration)
        {
            // 精简系统优化功能 - 无特殊配置（系统优化在快速模式下不需要）
            // 留空，系统优化在精简模式下不启用
        }

        public bool ValidateConfiguration(IConfiguration configuration)
        {
            // 系统优化中间件可以使用默认配置
            return true;
        }
    }
}
